home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / vibrant / vibgroup.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-07-05  |  34.5 KB  |  1,379 lines  |  [TEXT/R*ch]

  1. /*   vibgroup.c
  2. * ===========================================================================
  3. *
  4. *                            PUBLIC DOMAIN NOTICE
  5. *            National Center for Biotechnology Information (NCBI)
  6. *
  7. *  This software/database is a "United States Government Work" under the
  8. *  terms of the United States Copyright Act.  It was written as part of
  9. *  the author's official duties as a United States Government employee and
  10. *  thus cannot be copyrighted.  This software/database is freely available
  11. *  to the public for use. The National Library of Medicine and the U.S.
  12. *  Government do not place any restriction on its use or reproduction.
  13. *  We would, however, appreciate having the NCBI and the author cited in
  14. *  any work or product based on this material
  15. *
  16. *  Although all reasonable efforts have been taken to ensure the accuracy
  17. *  and reliability of the software and data, the NLM and the U.S.
  18. *  Government do not and cannot warrant the performance or results that
  19. *  may be obtained by using this software or data. The NLM and the U.S.
  20. *  Government disclaim all warranties, express or implied, including
  21. *  warranties of performance, merchantability or fitness for any particular
  22. *  purpose.
  23. *
  24. * ===========================================================================
  25. *
  26. * File Name:  vibgroup.c
  27. *
  28. * Author:  Jonathan Kans
  29. *
  30. * Version Creation Date:   7/1/91
  31. *
  32. * $Revision: 2.15 $
  33. *
  34. * File Description: 
  35. *       Vibrant group functions
  36. *
  37. * Modifications:  
  38. * --------------------------------------------------------------------------
  39. * Date     Name        Description of modification
  40. * -------  ----------  -----------------------------------------------------
  41. *
  42. *
  43. * ==========================================================================
  44. */
  45.  
  46. #include <vibtypes.h>
  47. #include <vibprocs.h>
  48. #include <vibincld.h>
  49.  
  50. #ifdef WIN_MAC
  51. #define Nlm_GroupTool Nlm_PrompT
  52. #define Nlm_LineTool  Nlm_Handle
  53. #endif
  54.  
  55. #ifdef WIN_MSWIN
  56. #define Nlm_GroupTool HWND
  57. #define Nlm_LineTool  Nlm_Handle
  58. #endif
  59.  
  60. #ifdef WIN_MOTIF
  61. #define Nlm_GroupTool Nlm_PrompT
  62. #define Nlm_LineTool  Widget
  63. #endif
  64.  
  65. typedef  struct  Nlm_groupdata {
  66.   Nlm_GroupTool  handle;
  67.   Nlm_LineTool   left;
  68.   Nlm_LineTool   top;
  69.   Nlm_LineTool   right;
  70.   Nlm_LineTool   bottom;
  71. } Nlm_GroupData;
  72.  
  73. typedef  struct  Nlm_grouprec {
  74.   Nlm_BoxRec     boxR;
  75.   Nlm_GroupData  group;
  76. } Nlm_GroupRec, PNTR Nlm_GrpPtr;
  77.  
  78. static Nlm_GphPrcsPtr  gphprcsptr = NULL;
  79.  
  80. static Nlm_GphPrcsPtr  groupProcs;
  81.  
  82. static Nlm_GrouP       recentGroup = NULL;
  83. static Nlm_GroupData   recentGroupData;
  84.  
  85. static void Nlm_LoadGroupData (Nlm_GrouP g, Nlm_GroupTool hdl,
  86.                                Nlm_LineTool lf, Nlm_LineTool tp,
  87.                                Nlm_LineTool rt, Nlm_LineTool bt)
  88.  
  89. {
  90.   Nlm_GrpPtr     gp;
  91.   Nlm_GroupData  PNTR gptr;
  92.  
  93.   if (g != NULL) {
  94.     gp = (Nlm_GrpPtr) Nlm_HandLock (g);
  95.     gptr = &(gp->group);
  96.     gptr->handle = hdl;
  97.     gptr->left = lf;
  98.     gptr->top = tp;
  99.     gptr->right = rt;
  100.     gptr->bottom = bt;
  101.     Nlm_HandUnlock (g);
  102.     recentGroup = NULL;
  103.   }
  104. }
  105.  
  106. static void Nlm_SetGroupData (Nlm_GrouP g, Nlm_GroupData * gdata)
  107.  
  108. {
  109.   Nlm_GrpPtr  gp;
  110.  
  111.   if (g != NULL && gdata != NULL) {
  112.     gp = (Nlm_GrpPtr) Nlm_HandLock (g);
  113.     gp->group = *gdata;
  114.     Nlm_HandUnlock (g);
  115.     recentGroup = g;
  116.     recentGroupData = *gdata;
  117.   }
  118. }
  119.  
  120. static void Nlm_GetGroupData (Nlm_GrouP g, Nlm_GroupData * gdata)
  121.  
  122. {
  123.   Nlm_GrpPtr  gp;
  124.  
  125.   if (g != NULL && gdata != NULL) {
  126.     if (g == recentGroup && NLM_RISKY) {
  127.       *gdata = recentGroupData;
  128.     } else {
  129.       gp = (Nlm_GrpPtr) Nlm_HandLock (g);
  130.       *gdata = gp->group;
  131.       Nlm_HandUnlock (g);
  132.       recentGroup = g;
  133.       recentGroupData = *gdata;
  134.     }
  135.   }
  136. }
  137.  
  138. static Nlm_GroupTool Nlm_GetGroupHandle (Nlm_GrouP g)
  139.  
  140. {
  141.   Nlm_GroupData  gdata;
  142.  
  143.   Nlm_GetGroupData (g, &gdata);
  144.   return gdata.handle;
  145. }
  146.  
  147. #ifdef WIN_MAC
  148. typedef struct revItem {
  149.   Nlm_GraphiC          graphic;
  150.   struct revItem  PNTR next;
  151. } Nlm_RevItem, PNTR Nlm_RevPtr;
  152.  
  153. static Nlm_Boolean Nlm_GroupClick (Nlm_GraphiC a, Nlm_PoinT pt)
  154.  
  155. {
  156.   Nlm_GraphiC  g;
  157.   Nlm_GraphiC  n;
  158.   Nlm_RevPtr   next;
  159.   Nlm_Boolean  notInside;
  160.   Nlm_RecT     r;
  161.   Nlm_Boolean  rsult;
  162.   Nlm_RevPtr   thisitem;
  163.   Nlm_RevPtr   top;
  164.  
  165.   rsult = FALSE;
  166.   Nlm_GetRect (a, &r);
  167.   if (Nlm_PtInRect (pt, &r)) {
  168.     g = Nlm_GetChild (a);
  169.     notInside = TRUE;
  170.     /*
  171.     while (g != NULL && notInside) {
  172.       n = Nlm_GetNext (g);
  173.       if (Nlm_GetEnabled (g) && Nlm_GetVisible (g) && Nlm_DoClick (g, pt)) {
  174.         notInside = FALSE;
  175.       }
  176.       g = n;
  177.     }
  178.     */
  179.     if (g != NULL && notInside) {
  180.       top = NULL;
  181.       while (g != NULL) {
  182.         thisitem = (Nlm_RevPtr) Nlm_MemNew (sizeof (Nlm_RevItem));
  183.         if (thisitem != NULL) {
  184.           thisitem->graphic = g;
  185.           thisitem->next = top;
  186.           top = thisitem;
  187.         }
  188.         g = Nlm_GetNext (g);
  189.       }
  190.       thisitem = top;
  191.       while (thisitem != NULL && notInside) {
  192.         next = thisitem->next;
  193.         g = thisitem->graphic;
  194.         if (Nlm_GetEnabled (g) && Nlm_GetVisible (g) && Nlm_DoClick (g, pt)) {
  195.           notInside = FALSE;
  196.         }
  197.         thisitem = next;
  198.       }
  199.       thisitem = top;
  200.       while (thisitem != NULL) {
  201.         next = thisitem->next;
  202.         Nlm_MemFree (thisitem);
  203.         thisitem = next;
  204.       }
  205.     }
  206.     rsult = (! notInside);
  207.   }
  208.   return rsult;
  209. }
  210.  
  211. static Nlm_Boolean Nlm_GroupKey (Nlm_GraphiC a, Nlm_Char ch)
  212.  
  213. {
  214.   Nlm_GraphiC  g;
  215.   Nlm_GraphiC  n;
  216.   Nlm_Boolean  notInside;
  217.  
  218.   g = Nlm_GetChild (a);
  219.   notInside = TRUE;
  220.   while (g != NULL && notInside) {
  221.     n = Nlm_GetNext (g);
  222.     if (Nlm_GetEnabled (g) && Nlm_GetVisible (g) && Nlm_DoKey (g, ch)) {
  223.       notInside = FALSE;
  224.     }
  225.     g = n;
  226.   }
  227.   return (! notInside);
  228. }
  229.  
  230. static void Nlm_DrawGroup (Nlm_GraphiC a)
  231.  
  232. {
  233.   Nlm_GraphiC    g;
  234.   Nlm_GroupTool  h;
  235.   Nlm_RecT       r;
  236.  
  237.   if (Nlm_GetVisible (a) && Nlm_GetAllParentsVisible (a)) {
  238.     Nlm_GetRect (a, &r);
  239.     Nlm_InsetRect (&r, -4, -4);
  240.     if (Nlm_RectInRgn (&r, Nlm_updateRgn)) {
  241.       Nlm_InsetRect (&r, 4, 4);
  242.       h = Nlm_GetGroupHandle ((Nlm_GrouP) a);
  243.       if (h != NULL) {
  244.         r.top += 6;
  245.         Nlm_FrameRect (&r);
  246.         Nlm_DoDraw ((Nlm_GraphiC) h);
  247.       }
  248.       g = Nlm_GetChild (a);
  249.       while (g != NULL) {
  250.         Nlm_DoDraw (g);
  251.         g = Nlm_GetNext (g);
  252.       }
  253.     }
  254.   }
  255. }
  256.  
  257. static Nlm_Boolean Nlm_IdleGroup (Nlm_GraphiC a, Nlm_PoinT pt)
  258.  
  259. {
  260.   Nlm_GraphiC  g;
  261.  
  262.   if (Nlm_GetVisible (a) && Nlm_GetEnabled (a)) {
  263.     g = Nlm_GetChild (a);
  264.     while (g != NULL) {
  265.       Nlm_DoIdle (g, pt);
  266.       g = Nlm_GetNext (g);
  267.     }
  268.   }
  269.   return TRUE;
  270. }
  271. #endif
  272.  
  273. static void Nlm_ShowGroup (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  274.  
  275. {
  276.   Nlm_GraphiC    g;
  277.   Nlm_GroupTool  h;
  278.   Nlm_WindoW     tempPort;
  279. #ifdef WIN_MAC
  280.   Nlm_RecT       r;
  281. #endif
  282. #ifdef WIN_MOTIF
  283.   Nlm_GroupData  gdata;
  284. #endif
  285.  
  286.   tempPort = Nlm_SavePortIfNeeded (a, savePort);
  287.   if (setFlag) {
  288.     Nlm_SetVisible (a, TRUE);
  289.   }
  290.   if (Nlm_GetVisible (a) && Nlm_AllParentsButWindowVisible (a)) {
  291.     h = Nlm_GetGroupHandle ((Nlm_GrouP) a);
  292.     if (h != NULL) {
  293. #ifdef WIN_MAC
  294.       if (Nlm_GetAllParentsVisible (a)) {
  295.         Nlm_GetRect (a, &r);
  296.         r.top += 6;
  297.         Nlm_FrameRect (&r);
  298.       }
  299.       Nlm_DoShow ((Nlm_GraphiC) h, TRUE, FALSE);
  300. #endif
  301. #ifdef WIN_MSWIN
  302.       ShowWindow (h, SW_SHOW);
  303.       UpdateWindow (h);
  304. #endif
  305. #ifdef WIN_MOTIF
  306.       Nlm_DoShow ((Nlm_GraphiC) h, TRUE, FALSE);
  307.       Nlm_GetGroupData ((Nlm_GrouP) a, &gdata);
  308.       XtManageChild (gdata.left);
  309.       XtManageChild (gdata.top);
  310.       XtManageChild (gdata.right);
  311.       XtManageChild (gdata.bottom);
  312. #endif
  313.     }
  314.     g = Nlm_GetChild (a);
  315.     while (g != NULL) {
  316.       Nlm_DoShow (g, FALSE, FALSE);
  317.       g = Nlm_GetNext (g);
  318.     }
  319.   }
  320.   Nlm_RestorePort (tempPort);
  321. }
  322.  
  323. static void Nlm_HideGroup (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  324.  
  325. {
  326.   Nlm_GraphiC    g;
  327.   Nlm_GroupTool  h;
  328.   Nlm_WindoW     tempPort;
  329. #ifdef WIN_MAC
  330.   Nlm_RecT       r;
  331. #endif
  332. #ifdef WIN_MOTIF
  333.   Nlm_GroupData  gdata;
  334. #endif
  335.  
  336.   tempPort = Nlm_SavePortIfNeeded (a, savePort);
  337.   if (Nlm_AllParentsButWindowVisible (a)) {
  338.     h = Nlm_GetGroupHandle ((Nlm_GrouP) a);
  339. #ifdef WIN_MAC
  340.     if (h != NULL) {
  341.       Nlm_DoHide ((Nlm_GraphiC) h, TRUE, FALSE);
  342.     }
  343.     if (Nlm_GetAllParentsVisible (a)) {
  344.       Nlm_GetRect (a, &r);
  345.       Nlm_InsetRect (&r, -1, -1);
  346.       /*
  347.       Nlm_InvalRect (&r);
  348.       */
  349.       Nlm_EraseRect (&r);
  350.       Nlm_ValidRect (&r);
  351.     }
  352. #endif
  353.     g = Nlm_GetChild (a);
  354.     while (g != NULL) {
  355.       Nlm_DoHide (g, FALSE, FALSE);
  356.       g = Nlm_GetNext (g);
  357.     }
  358. #ifdef WIN_MSWIN
  359.     if (h != NULL) {
  360.       ShowWindow (h, SW_HIDE);
  361.       UpdateWindow (h);
  362.     }
  363. #endif
  364. #ifdef WIN_MOTIF
  365.     if (h != NULL) {
  366.       Nlm_DoHide ((Nlm_GraphiC) h, TRUE, FALSE);
  367.       Nlm_GetGroupData ((Nlm_GrouP) a, &gdata);
  368.       XtUnmanageChild (gdata.left);
  369.       XtUnmanageChild (gdata.top);
  370.       XtUnmanageChild (gdata.right);
  371.       XtUnmanageChild (gdata.bottom);
  372.     }
  373. #endif
  374.   }
  375.   if (setFlag) {
  376.     Nlm_SetVisible (a, FALSE);
  377.   }
  378.   Nlm_RestorePort (tempPort);
  379. }
  380.  
  381. static void Nlm_EnableGroup (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  382.  
  383. {
  384.   Nlm_GraphiC    g;
  385.   Nlm_GroupTool  h;
  386.   Nlm_WindoW     tempPort;
  387.  
  388.   tempPort = Nlm_SavePortIfNeeded (a, savePort);
  389.   if (setFlag) {
  390.     Nlm_SetEnabled (a, TRUE);
  391.   }
  392.   if (Nlm_GetEnabled (a) && Nlm_GetAllParentsEnabled (a)) {
  393.     h = Nlm_GetGroupHandle ((Nlm_GrouP) a);
  394.     if (h != NULL) {
  395. #ifdef WIN_MAC
  396.       Nlm_DoEnable ((Nlm_GraphiC) h, TRUE, FALSE);
  397. #endif
  398. #ifdef WIN_MSWIN
  399.       EnableWindow (h, TRUE);
  400. #endif
  401. #ifdef WIN_MOTIF
  402.       Nlm_DoEnable ((Nlm_GraphiC) h, TRUE, FALSE);
  403. #endif
  404.     }
  405.     g = Nlm_GetChild (a);
  406.     while (g != NULL) {
  407.       Nlm_DoEnable (g, FALSE, FALSE);
  408.       g = Nlm_GetNext (g);
  409.     }
  410.   }
  411.   Nlm_RestorePort (tempPort);
  412. }
  413.  
  414. static void Nlm_DisableGroup (Nlm_GraphiC a, Nlm_Boolean setFlag, Nlm_Boolean savePort)
  415.  
  416. {
  417.   Nlm_GraphiC    g;
  418.   Nlm_GroupTool  h;
  419.   Nlm_WindoW     tempPort;
  420.  
  421.   tempPort = Nlm_SavePortIfNeeded (a, savePort);
  422.   if (setFlag) {
  423.     Nlm_SetEnabled (a, FALSE);
  424.   }
  425.   h = Nlm_GetGroupHandle ((Nlm_GrouP) a);
  426.   if (h != NULL) {
  427. #ifdef WIN_MAC
  428.     Nlm_DoDisable ((Nlm_GraphiC) h, TRUE, FALSE);
  429. #endif
  430. #ifdef WIN_MSWIN
  431.     EnableWindow (h, FALSE);
  432. #endif
  433. #ifdef WIN_MOTIF
  434.     Nlm_DoDisable ((Nlm_GraphiC) h, TRUE, FALSE);
  435. #endif
  436.   }
  437.   g = Nlm_GetChild (a);
  438.   while (g != NULL) {
  439.     Nlm_DoDisable (g, FALSE, FALSE);
  440.     g = Nlm_GetNext (g);
  441.   }
  442.   Nlm_RestorePort (tempPort);
  443. }
  444.  
  445. static void Nlm_ActivateGroup (Nlm_GraphiC a, Nlm_Boolean savePort)
  446.  
  447. {
  448.   Nlm_GraphiC  g;
  449.  
  450.   g = Nlm_GetChild (a);
  451.   while (g != NULL) {
  452.     Nlm_DoActivate (g, FALSE);
  453.     g = Nlm_GetNext (g);
  454.   }
  455. }
  456.  
  457. static void Nlm_DeactivateGroup (Nlm_GraphiC a, Nlm_Boolean savePort)
  458.  
  459. {
  460.   Nlm_GraphiC  g;
  461.  
  462.   g = Nlm_GetChild (a);
  463.   while (g != NULL) {
  464.     Nlm_DoDeactivate (g, FALSE);
  465.     g = Nlm_GetNext (g);
  466.   }
  467. }
  468.  
  469. static void Nlm_ResetGroup (Nlm_GraphiC a, Nlm_Boolean savePort)
  470.  
  471. {
  472.   Nlm_GraphiC  g;
  473.   Nlm_GraphiC  n;
  474.   Nlm_WindoW   tempPort;
  475.  
  476.   tempPort = Nlm_SavePortIfNeeded (a, savePort);
  477.   g = Nlm_GetChild (a);
  478.   while (g != NULL) {
  479.     n = Nlm_GetNext (g);
  480.     Nlm_DoReset (g, FALSE);
  481.     g = n;
  482.   }
  483.   Nlm_RestorePort (tempPort);
  484. }
  485.  
  486. static void Nlm_RemoveGroup (Nlm_GraphiC a, Nlm_Boolean savePort)
  487.  
  488. {
  489.   Nlm_GraphiC    g;
  490.   Nlm_GroupTool  h;
  491.   Nlm_GraphiC    n;
  492.   Nlm_WindoW     tempPort;
  493. #ifdef WIN_MOTIF
  494.   Nlm_GroupData  gdata;
  495. #endif
  496.  
  497.   tempPort = Nlm_SavePortIfNeeded (a, savePort);
  498.   g = Nlm_GetChild (a);
  499.   while (g != NULL) {
  500.     n = Nlm_GetNext (g);
  501.     Nlm_DoRemove (g, FALSE);
  502.     g = n;
  503.   }
  504.   h = Nlm_GetGroupHandle ((Nlm_GrouP) a);
  505.   if (h != NULL) {
  506. #ifdef WIN_MAC
  507.     Nlm_DoRemove ((Nlm_GraphiC) h, FALSE);
  508. #endif
  509. #ifdef WIN_MSWIN
  510.     DestroyWindow (h);
  511. #endif
  512. #ifdef WIN_MOTIF
  513.     Nlm_DoRemove ((Nlm_GraphiC) h, FALSE);
  514.     Nlm_GetGroupData ((Nlm_GrouP) a, &gdata);
  515.     XtDestroyWidget (gdata.left);
  516.     XtDestroyWidget (gdata.top);
  517.     XtDestroyWidget (gdata.right);
  518.     XtDestroyWidget (gdata.bottom);
  519. #endif
  520.   }
  521.   Nlm_RemoveLink (a);
  522.   recentGroup = NULL;
  523.   Nlm_RestorePort (tempPort);
  524. }
  525.  
  526. static void Nlm_SetGroupTitle (Nlm_GraphiC a, Nlm_Int2 item,
  527.                                Nlm_CharPtr title, Nlm_Boolean savePort)
  528.  
  529. {
  530.   Nlm_GraphiC    g;
  531.   Nlm_GroupTool  h;
  532.   Nlm_WindoW     tempPort;
  533.  
  534.   tempPort = Nlm_SavePortIfNeeded (a, savePort);
  535.   if (item > 0) {
  536.     g = Nlm_FindItem (a, item);
  537.     if (g != NULL) {
  538.       Nlm_DoSetTitle (g, 0, title, FALSE);
  539.     }
  540.   } else {
  541.     h = Nlm_GetGroupHandle ((Nlm_GrouP) a);
  542.     if (h != NULL) {
  543. #ifdef WIN_MAC
  544.       Nlm_DoSetTitle ((Nlm_GraphiC) h, 0, title, FALSE);
  545. #endif
  546. #ifdef WIN_MSWIN
  547.       SetWindowText (h, title);
  548. #endif
  549. #ifdef WIN_MOTIF
  550. #endif
  551.     }
  552.   }
  553.   Nlm_RestorePort (tempPort);
  554. }
  555.  
  556. static void Nlm_GetGroupTitle (Nlm_GraphiC a, Nlm_Int2 item,
  557.                                Nlm_CharPtr title, Nlm_sizeT maxsize)
  558.  
  559. {
  560.   Nlm_GraphiC    g;
  561.   Nlm_GroupTool  h;
  562.   Nlm_Char       temp [256];
  563.  
  564.   if (item > 0) {
  565.     g = Nlm_FindItem (a, item);
  566.     if (g != NULL) {
  567.       Nlm_DoGetTitle (g, 0, title, maxsize);
  568.     }
  569.   } else {
  570.     h = Nlm_GetGroupHandle ((Nlm_GrouP) a);
  571.     if (h != NULL) {
  572. #ifdef WIN_MAC
  573.       Nlm_DoGetTitle ((Nlm_GraphiC) h, 0, title, maxsize);
  574. #endif
  575. #ifdef WIN_MSWIN
  576.       GetWindowText (h, temp, sizeof (temp));
  577.       Nlm_StringNCpy (title, temp, maxsize);
  578. #endif
  579. #ifdef WIN_MOTIF
  580. #endif
  581.     }
  582.   }
  583. }
  584.  
  585. static void Nlm_SetGroupValue (Nlm_GraphiC a, Nlm_Int2 value, Nlm_Boolean savePort)
  586.  
  587. {
  588.   Nlm_GraphiC  g;
  589.   Nlm_WindoW   tempPort;
  590.  
  591.   tempPort = Nlm_SavePortIfNeeded (a, savePort);
  592.   if (value > 0) {
  593.     g = Nlm_FindItem (a, value);
  594.     Nlm_ClearItemsInGroup (a, g, FALSE);
  595.     if (g != NULL) {
  596.       Nlm_DoSetStatus (g, 0, TRUE, FALSE);
  597.     }
  598.   } else {
  599.     Nlm_ClearItemsInGroup (a, NULL, FALSE);
  600.   }
  601.   Nlm_RestorePort (tempPort);
  602. }
  603.  
  604. static Nlm_Int2 Nlm_GetGroupValue (Nlm_GraphiC a)
  605.  
  606. {
  607.   Nlm_Boolean  found;
  608.   Nlm_GraphiC  g;
  609.   Nlm_Int2     i;
  610.   Nlm_Int2     rsult;
  611.  
  612.   rsult = FALSE;
  613.   g = Nlm_GetChild (a);
  614.   i = 0;
  615.   found = FALSE;
  616.   while (g != NULL && ! found) {
  617.     i++;
  618.     found = Nlm_DoGetStatus (g, 0);
  619.     g = Nlm_GetNext (g);
  620.   }
  621.   if (found) {
  622.     rsult = i;
  623.   }
  624.   return rsult;
  625. }
  626.  
  627. static void Nlm_SetGroupStatus (Nlm_GraphiC a, Nlm_Int2 item,
  628.                                 Nlm_Boolean value, Nlm_Boolean savePort)
  629.  
  630. {
  631.   Nlm_GraphiC  g;
  632.   Nlm_WindoW   tempPort;
  633.  
  634.   tempPort = Nlm_SavePortIfNeeded (a, savePort);
  635.   if (item > 0) {
  636.     g = Nlm_FindItem (a, item);
  637.     if (g != NULL) {
  638.       Nlm_DoSetStatus (g, 0, value, FALSE);
  639.     }
  640.   }
  641.   Nlm_RestorePort (tempPort);
  642. }
  643.  
  644. static Nlm_Boolean Nlm_GetGroupStatus (Nlm_GraphiC a, Nlm_Int2 item)
  645.  
  646. {
  647.   Nlm_GraphiC  g;
  648.   Nlm_Boolean  rsult;
  649.  
  650.   rsult = FALSE;
  651.   if (item > 0) {
  652.     g = Nlm_FindItem (a, item);
  653.     if (g != NULL) {
  654.       rsult = Nlm_DoGetStatus (g, 0);
  655.     }
  656.   }
  657.   return rsult;
  658. }
  659.  
  660. #ifdef WIN_MAC
  661. static void Nlm_InvalItem (Nlm_GraphiC a)
  662.  
  663. {
  664.   Nlm_RecT  r;
  665.  
  666.   if (Nlm_GetVisible (a) && Nlm_GetAllParentsVisible (a)) {
  667.     Nlm_GetRect (a, &r);
  668.     Nlm_InsetRect (&r, -1, -1);
  669.     Nlm_InvalRect (&r);
  670.   }
  671. }
  672. #endif
  673.  
  674. static void Nlm_InvalGroup (Nlm_GraphiC a)
  675.  
  676. {
  677.   Nlm_RecT        r;
  678. #ifdef WIN_MSWIN
  679.   Nlm_RectTool    rtool;
  680.   Nlm_WindowTool  wptr;
  681. #endif
  682.  
  683.   if (Nlm_GetVisible (a) && Nlm_GetAllParentsVisible (a)) {
  684. #ifdef WIN_MAC
  685.     Nlm_GetRect (a, &r);
  686.     Nlm_InsetRect (&r, -1, -1);
  687.     Nlm_InvalRect (&r);
  688. #endif
  689. #ifdef WIN_MSWIN
  690.     wptr = Nlm_ParentWindowPtr (a);
  691.     Nlm_GetRect (a, &r);
  692.     r.top = r.bottom - 1;
  693.     r.bottom++;
  694.     Nlm_RecTToRectTool (&r, &rtool);
  695.     InvalidateRect (wptr, &rtool, TRUE);
  696.     Nlm_GetRect (a, &r);
  697.     r.left = r.right - 1;
  698.     r.right++;
  699.     Nlm_RecTToRectTool (&r, &rtool);
  700.     InvalidateRect (wptr, &rtool, TRUE);
  701. #endif
  702. #ifdef WIN_MOTIF
  703. #endif
  704.   }
  705. }
  706.  
  707. static void Nlm_SetGroupPosition (Nlm_GraphiC a, Nlm_RectPtr r, Nlm_Boolean savePort)
  708.  
  709. {
  710.   Nlm_GraphiC    g;
  711.   Nlm_RecT       gr;
  712.   Nlm_GroupTool  h;
  713.   Nlm_RecT       oldRect;
  714.   Nlm_WindoW     tempPort;
  715.   Nlm_Int2       deltaX;
  716.   Nlm_Int2       deltaY;
  717. #ifdef WIN_MAC
  718.   Nlm_Int2       deltaH;
  719.   Nlm_Int2       deltaW;
  720. #endif
  721. #ifdef WIN_MOTIF
  722.   Nlm_Int2       deltaH;
  723.   Nlm_Int2       deltaW;
  724.   Nlm_GroupData  gdata;
  725. #endif
  726.  
  727.   if (r != NULL) {
  728.     Nlm_DoGetPosition (a, &oldRect);
  729.     if (! Nlm_EqualRect (r, &oldRect)) {
  730.       tempPort = Nlm_SavePortIfNeeded (a, savePort);
  731.       Nlm_GetRect (a, &oldRect);
  732.       gr = *r;
  733.       deltaX = gr.left - oldRect.left;
  734.       deltaY = gr.top - oldRect.top;
  735. #ifdef WIN_MAC
  736.       deltaW = (gr.right - gr.left) - (oldRect.right - oldRect.left);
  737.       deltaH = (gr.bottom - gr.top) - (oldRect.bottom - oldRect.top);
  738. #endif
  739. #ifdef WIN_MOTIF
  740.       deltaW = (gr.right - gr.left) - (oldRect.right - oldRect.left);
  741.       deltaH = (gr.bottom - gr.top) - (oldRect.bottom - oldRect.top);
  742. #endif
  743.       Nlm_InvalGroup (a);
  744.       Nlm_SetRect (a, &gr);
  745.       h = Nlm_GetGroupHandle ((Nlm_GrouP) a);
  746.       if (h != NULL) {
  747. #ifdef WIN_MAC
  748.         Nlm_GetRect ((Nlm_GraphiC) h, &gr);
  749.         Nlm_UpsetRect (&gr, deltaX, deltaY, -deltaX, -deltaY);
  750.         Nlm_DoSetPosition ((Nlm_GraphiC) h, &gr, FALSE);
  751. #endif
  752. #ifdef WIN_MSWIN
  753.         MoveWindow (h, gr.left, gr.top, gr.right - gr.left, gr.bottom - gr.top, TRUE);
  754. #endif
  755. #ifdef WIN_MOTIF
  756.         Nlm_GetRect ((Nlm_GraphiC) h, &gr);
  757.         Nlm_UpsetRect (&gr, deltaX, deltaY, -deltaX, -deltaY);
  758.         Nlm_DoSetPosition ((Nlm_GraphiC) h, &gr, FALSE);
  759.         Nlm_GetRect (a, &gr);
  760.         gr.top += Nlm_stdLineHeight / 2;
  761.         Nlm_GetGroupData ((Nlm_GrouP) a, &gdata);
  762.         XtVaSetValues (gdata.left,
  763.                        XmNx, (Position) gr.left,
  764.                        XmNy, (Position) gr.top,
  765.                        XmNwidth, (Dimension) 1,
  766.                        XmNheight, (Dimension) (gr.bottom - gr.top), 
  767.                        NULL);
  768.         XtVaSetValues (gdata.top,
  769.                        XmNx, (Position) gr.left,
  770.                        XmNy, (Position) gr.top,
  771.                        XmNwidth, (Dimension) (gr.right - gr.left),
  772.                        XmNheight, (Dimension) 1, 
  773.                        NULL);
  774.         XtVaSetValues (gdata.right,
  775.                        XmNx, (Position) gr.right,
  776.                        XmNy, (Position) gr.top,
  777.                        XmNwidth, (Dimension) 1,
  778.                        XmNheight, (Dimension) (gr.bottom - gr.top), 
  779.                        NULL);
  780.         XtVaSetValues (gdata.bottom,
  781.                        XmNx, (Position) gr.left,
  782.                        XmNy, (Position) gr.bottom,
  783.                        XmNwidth, (Dimension) (gr.right - gr.left + 1),
  784.                        XmNheight, (Dimension) 1, 
  785.                        NULL);
  786. #endif
  787. #ifdef WIN_MAC
  788.         Nlm_InvalGroup (a);
  789. #endif
  790.       }
  791.       g = Nlm_GetChild (a);
  792.       while (g != NULL) {
  793.         Nlm_DoGetPosition (g, &gr);
  794.         Nlm_OffsetRect (&gr, deltaX, deltaY);
  795.         Nlm_DoSetPosition (g, &gr, FALSE);
  796.         g = Nlm_GetNext (g);
  797.       }
  798. #ifdef WIN_MSWIN
  799.       if (h != NULL) {
  800.         UpdateWindow (h);
  801.       }
  802. #endif
  803. #ifdef WIN_MOTIF
  804. #endif
  805.       Nlm_RestorePort (tempPort);
  806.     }
  807.   }
  808. }
  809.  
  810. static void Nlm_GetGroupPosition (Nlm_GraphiC a, Nlm_RectPtr r)
  811.  
  812. {
  813.   Nlm_RecT  gr;
  814.  
  815.   Nlm_GetRect (a, &gr);
  816.   if (r != NULL) {
  817.     *r = gr;
  818.   }
  819. }
  820.  
  821. static Nlm_GraphiC Nlm_GroupGainFocus (Nlm_GraphiC a, Nlm_Char ch, Nlm_Boolean savePort)
  822.  
  823. {
  824.   Nlm_GraphiC  p;
  825.   Nlm_GraphiC  q;
  826.  
  827.   q = NULL;
  828.   if (Nlm_GetVisible (a) && Nlm_GetEnabled (a)) {
  829.     p = Nlm_GetChild (a);
  830.     while (p != NULL && q == NULL) {
  831.       q = Nlm_DoGainFocus (p, ch, savePort);
  832.       p = Nlm_GetNext (p);
  833.     }
  834.   }
  835.   return q;
  836. }
  837.  
  838. static void Nlm_GroupLoseFocus (Nlm_GraphiC a, Nlm_GraphiC excpt, Nlm_Boolean savePort)
  839.  
  840. {
  841.   Nlm_GraphiC  p;
  842.  
  843.   p = Nlm_GetChild (a);
  844.   while (p != NULL) {
  845.     Nlm_DoLoseFocus (p, excpt, savePort);
  846.     p = Nlm_GetNext (p);
  847.   }
  848. }
  849.  
  850. static void Nlm_RepositionHorizItems (Nlm_GraphiC a, Nlm_Int2 count,
  851.                                       Nlm_Int2 width, Nlm_Boolean align)
  852.  
  853. {
  854.   Nlm_BoxData  bdata;
  855.   Nlm_Int2     col;
  856.   Nlm_Int2     column;
  857.   Nlm_Int2     curWdt;
  858.   Nlm_GrouP    g;
  859.   Nlm_Int2     i;
  860.   Nlm_Int2     newWdt;
  861.   Nlm_Int2     offset;
  862.   Nlm_GraphiC  p;
  863.   Nlm_RecT     r;
  864.   Nlm_RecT     s;
  865.   Nlm_GraphiC  top;
  866.   Nlm_RecT     topRect;
  867.   Nlm_Int2     topWdt;
  868.  
  869.   column = (count - 1) % width + 1;
  870.   g = (Nlm_GrouP) Nlm_GetParent (a);
  871.   top = Nlm_FindItem ((Nlm_GraphiC) g, column);
  872.   Nlm_DoGetPosition (a, &r);
  873.   Nlm_DoGetPosition (top, &topRect);
  874.   curWdt = r.right - r.left;
  875.   topWdt = topRect.right - topRect.left;
  876.   newWdt = MAX (curWdt, topWdt);
  877.   if (curWdt < newWdt) {
  878.     r.right = r.left + newWdt;
  879.     Nlm_DoSetPosition (a, &r, FALSE);
  880.     curWdt = newWdt;
  881.   }
  882.   if (newWdt > topWdt) {
  883.     offset = newWdt - topWdt;
  884.     i = 1;
  885.     p = Nlm_GetChild ((Nlm_GraphiC) g);
  886.     while (p != NULL) {
  887.       col = (i - 1) % width + 1;
  888.       if (col == column) {
  889.         Nlm_DoGetPosition (p, &r);
  890.         r.right = r.left + newWdt;
  891.         Nlm_DoSetPosition (p, &r, FALSE);
  892.         Nlm_RecordRect ((Nlm_GraphiC) g, &r);
  893.       } else if (col > column) {
  894.         Nlm_DoGetPosition (p, &r);
  895.         Nlm_OffsetRect (&r, offset, 0);
  896.         Nlm_DoSetPosition (p, &r, FALSE);
  897.         Nlm_RecordRect ((Nlm_GraphiC) g, &r);
  898.       }
  899.       i++;
  900.       p = Nlm_GetNext (p);
  901.     }
  902.   }
  903.   Nlm_GetRect ((Nlm_GraphiC) g, &r);
  904.   Nlm_GetRect ((Nlm_GraphiC) g, &s);
  905.   Nlm_GetBoxData ((Nlm_BoX) g, &bdata);
  906.   s.right = MAX (r.right, bdata.limitPoint.x + bdata.xMargin);
  907.   s.bottom = bdata.limitPoint.y + bdata.yMargin;
  908.   Nlm_SetRect ((Nlm_GraphiC) g, &s);
  909.   r.right = bdata.limitPoint.x + bdata.xMargin;
  910.   r.bottom = bdata.limitPoint.y + bdata.yMargin;
  911.   Nlm_DoAdjustPrnt ((Nlm_GraphiC) g, &r, align, FALSE);
  912.   Nlm_DoGetPosition (a, &r);
  913.   bdata.nextCol = r.right + bdata.xSpacing;
  914.   Nlm_SetBoxData ((Nlm_BoX) g, &bdata);
  915. }
  916.  
  917. static void Nlm_RepositionVertItems (Nlm_GraphiC a, Nlm_Int2 count,
  918.                                      Nlm_Int2 height, Nlm_Boolean align)
  919.  
  920. {
  921.   Nlm_BoxData  bdata;
  922.   Nlm_Int2     column;
  923.   Nlm_Int2     curWdt;
  924.   Nlm_GrouP    g;
  925.   Nlm_Int2     newWdt;
  926.   Nlm_GraphiC  p;
  927.   Nlm_RecT     r;
  928.   Nlm_RecT     s;
  929.   Nlm_GraphiC  top;
  930.   Nlm_RecT     topRect;
  931.   Nlm_Int2     topWdt;
  932.  
  933.   column = (count - 1) / height + 1;
  934.   g = (Nlm_GrouP) Nlm_GetParent (a);
  935.   top = Nlm_FindItem ((Nlm_GraphiC) g, (column - 1) * height + 1);
  936.   Nlm_DoGetPosition (a, &r);
  937.   Nlm_DoGetPosition (top, &topRect);
  938.   curWdt = r.right - r.left;
  939.   topWdt = topRect.right - topRect.left;
  940.   newWdt = MAX (curWdt, topWdt);
  941.   if (curWdt < newWdt) {
  942.     r.right = r.left + newWdt;
  943.     Nlm_DoSetPosition (a, &r, FALSE);
  944.     Nlm_RecordRect ((Nlm_GraphiC) g, &r);
  945.     curWdt = newWdt;
  946.   }
  947.   if (newWdt > topWdt) {
  948.     p = top;
  949.     while (p != NULL && p != a) {
  950.       Nlm_DoGetPosition (p, &r);
  951.       r.right = r.left + newWdt;
  952.       Nlm_DoSetPosition (p, &r, FALSE);
  953.       Nlm_RecordRect ((Nlm_GraphiC) g, &r);
  954.       p = Nlm_GetNext (p);
  955.     }
  956.   }
  957.   Nlm_GetRect ((Nlm_GraphiC) g, &r);
  958.   Nlm_GetRect ((Nlm_GraphiC) g, &s);
  959.   Nlm_GetBoxData ((Nlm_BoX) g, &bdata);
  960.   s.right = MAX (r.right, bdata.limitPoint.x + bdata.xMargin);
  961.   s.bottom = bdata.limitPoint.y + bdata.yMargin;
  962.   Nlm_SetRect ((Nlm_GraphiC) g, &s);
  963.   r.right = bdata.limitPoint.x + bdata.xMargin;
  964.   r.bottom = bdata.limitPoint.y + bdata.yMargin;
  965.   Nlm_DoAdjustPrnt ((Nlm_GraphiC) g, &r, align, FALSE);
  966.   Nlm_DoGetPosition (a, &r);
  967.   bdata.nextCol = r.right + bdata.xSpacing;
  968.   Nlm_SetBoxData ((Nlm_BoX) g, &bdata);
  969. }
  970.  
  971. static void Nlm_FinishItemPositioning (Nlm_GraphiC a, Nlm_RectPtr subRect,
  972.                                        Nlm_Boolean align, Nlm_Boolean savePort)
  973.  
  974. {
  975.   Nlm_BoxData    bdata;
  976.   Nlm_Int2       count;
  977.   Nlm_GrouP      g;
  978.   Nlm_Int2       height;
  979.   Nlm_RecT       r;
  980.   Nlm_RecT       s;
  981.   Nlm_WindoW     tempPort;
  982.   Nlm_Int2       width;
  983. #ifdef WIN_MSWIN
  984.   Nlm_GroupTool  h;
  985. #endif
  986. #ifdef WIN_MOTIF
  987.   Nlm_GroupData  gdata;
  988.   Nlm_RecT       gr;
  989.   Nlm_GroupTool  h;
  990. #endif
  991.  
  992.   tempPort = Nlm_SavePortIfNeeded (a, savePort);
  993.   g = (Nlm_GrouP) Nlm_GetParent (a);
  994.   Nlm_InvalGroup ((Nlm_GraphiC) g);
  995.   Nlm_RecordRect ((Nlm_GraphiC) g, subRect);
  996.   if (align) {
  997.     Nlm_GetBoxData ((Nlm_BoX) g, &bdata);
  998.     if (bdata.boxWidth != 0 || bdata.boxHeight != 0) {
  999.       Nlm_NextPosition ((Nlm_GraphiC) g, subRect);
  1000.     }
  1001.   }
  1002.   Nlm_GetRect ((Nlm_GraphiC) g, &r);
  1003.   Nlm_GetRect ((Nlm_GraphiC) g, &s);
  1004.   Nlm_GetBoxData ((Nlm_BoX) g, &bdata);
  1005.   s.right = MAX (r.right, bdata.limitPoint.x + bdata.xMargin);
  1006.   s.bottom = bdata.limitPoint.y + bdata.yMargin;
  1007.   Nlm_SetRect ((Nlm_GraphiC) g, &s);
  1008.   r.right = bdata.limitPoint.x + bdata.xMargin;
  1009.   r.bottom = bdata.limitPoint.y + bdata.yMargin;
  1010.   Nlm_DoAdjustPrnt ((Nlm_GraphiC) g, &r, align, FALSE);
  1011.   if (align) {
  1012.     count = Nlm_CountGroupItems ((Nlm_GraphiC) g);
  1013.     width = bdata.boxWidth;
  1014.     height = bdata.boxHeight;
  1015.     if (width != 0) {
  1016.       if (width > 0 && count > width) {
  1017.         Nlm_RepositionHorizItems (a, count, width, align);
  1018.       }
  1019.       Nlm_Advance ((Nlm_GraphiC) g);
  1020.       if ((count %  ABS (width)) == 0) {
  1021.         Nlm_Break ((Nlm_GraphiC) g);
  1022.       }
  1023.     } else if (height != 0) {
  1024.       if (height > 0 && count > 1) {
  1025.         Nlm_RepositionVertItems (a, count, height, align);
  1026.       }
  1027.       if ((count % ABS (height)) == 0) {
  1028.         Nlm_Advance ((Nlm_GraphiC) g);
  1029.       }
  1030.     }
  1031.   }
  1032. #ifdef WIN_MAC
  1033.   Nlm_InvalGroup ((Nlm_GraphiC) g);
  1034.   Nlm_InvalItem (a);
  1035. #endif
  1036. #ifdef WIN_MSWIN
  1037.   Nlm_GetRect ((Nlm_GraphiC) g, &r);
  1038.   h = Nlm_GetGroupHandle (g);
  1039.   if (h != NULL) {
  1040.     MoveWindow (h, r.left, r.top, r.right - r.left, r.bottom - r.top, TRUE);
  1041.     UpdateWindow (h);
  1042.   }
  1043. #endif
  1044. #ifdef WIN_MOTIF
  1045.   h = Nlm_GetGroupHandle (g);
  1046.   if (h != NULL) {
  1047.     Nlm_GetRect ((Nlm_GraphiC) g, &gr);
  1048.     gr.top += Nlm_stdLineHeight / 2;
  1049.     Nlm_GetGroupData ((Nlm_GrouP) g, &gdata);
  1050.     XtVaSetValues (gdata.left,
  1051.                    XmNx, (Position) gr.left,
  1052.                    XmNy, (Position) gr.top,
  1053.                    XmNwidth, (Dimension) 1,
  1054.                    XmNheight, (Dimension) (gr.bottom - gr.top), 
  1055.                    NULL);
  1056.     XtVaSetValues (gdata.top,
  1057.                    XmNx, (Position) gr.left,
  1058.                    XmNy, (Position) gr.top,
  1059.                    XmNwidth, (Dimension) (gr.right - gr.left),
  1060.                    XmNheight, (Dimension) 1, 
  1061.                    NULL);
  1062.     XtVaSetValues (gdata.right,
  1063.                    XmNx, (Position) gr.right,
  1064.                    XmNy, (Position) gr.top,
  1065.                    XmNwidth, (Dimension) 1,
  1066.                    XmNheight, (Dimension) (gr.bottom - gr.top), 
  1067.                    NULL);
  1068.     XtVaSetValues (gdata.bottom,
  1069.                    XmNx, (Position) gr.left,
  1070.                    XmNy, (Position) gr.bottom,
  1071.                    XmNwidth, (Dimension) (gr.right - gr.left + 1),
  1072.                    XmNheight, (Dimension) 1, 
  1073.                    NULL);
  1074.   }
  1075. #endif
  1076.   Nlm_RestorePort (tempPort);
  1077. }
  1078.  
  1079. #ifdef WIN_MOTIF
  1080. static Nlm_LineTool Nlm_CreateSeparator (Nlm_GrouP g, Nlm_RectPtr gr, Nlm_Int2 which)
  1081.  
  1082. {
  1083.   Nlm_LineTool    h;
  1084.   Dimension       height;
  1085.   Cardinal        n;
  1086.   unsigned char   orient;
  1087.   Nlm_RecT        r;
  1088.   unsigned char   separat;
  1089.   Arg             wargs [20];
  1090.   Dimension       width;
  1091.   Nlm_WindowTool  wptr;
  1092.  
  1093.   r = *gr;
  1094.   r.top += Nlm_stdLineHeight / 2;
  1095.   switch (which) {
  1096.     case 1:
  1097.       orient = XmVERTICAL;
  1098.       separat = XmSINGLE_LINE;
  1099.       r.right = r.left;
  1100.       width = (Dimension) 1;
  1101.       height = (Dimension) (r.bottom - r.top);
  1102.       break;
  1103.     case 2:
  1104.       orient = XmHORIZONTAL;
  1105.       separat = XmSINGLE_LINE;
  1106.       r.bottom = r.top;
  1107.       width = (Dimension) (r.right - r.left);
  1108.       height = (Dimension) 1;
  1109.       break;
  1110.     case 3:
  1111.       orient = XmVERTICAL;
  1112.       separat = XmSINGLE_LINE;
  1113.       r.left = r.right;
  1114.       width = (Dimension) 1;
  1115.       height = (Dimension) (r.bottom - r.top);
  1116.       break;
  1117.     case 4:
  1118.       orient = XmHORIZONTAL;
  1119.       separat = XmSINGLE_LINE;
  1120.       r.top = r.bottom;
  1121.       width = (Dimension) (r.right - r.left + 1);
  1122.       height = (Dimension) 1;
  1123.       break;
  1124.     default:
  1125.       width = (Dimension) (r.right - r.left);
  1126.       height = (Dimension) (r.bottom - r.top);
  1127.       orient = XmHORIZONTAL;
  1128.       separat = XmSINGLE_LINE;
  1129.       break;
  1130.   }
  1131.   n = 0;
  1132.   XtSetArg (wargs [n], XmNx, (Position) r.left); n++;
  1133.   XtSetArg (wargs [n], XmNy, (Position) r.top); n++;
  1134.   XtSetArg (wargs [n], XmNwidth, (Dimension) width); n++;
  1135.   XtSetArg (wargs [n], XmNheight, (Dimension) height); n++;
  1136.   XtSetArg (wargs [n], XmNmarginHeight, 0); n++;
  1137.   XtSetArg (wargs [n], XmNmarginWidth, 0); n++;
  1138.   XtSetArg (wargs [n], XmNborderWidth, (Dimension) 0); n++;
  1139.   XtSetArg (wargs [n], XmNmargin, (Dimension) 0); n++;
  1140.   XtSetArg (wargs [n], XmNhighlightThickness, (Dimension) 0); n++;
  1141.   XtSetArg (wargs [n], XmNshadowThickness, (Dimension) 0); n++;
  1142.   XtSetArg (wargs [n], XmNorientation, orient); n++;
  1143.   XtSetArg (wargs [n], XmNseparatorType, separat); n++;
  1144.   wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) g);
  1145.   h = XmCreateSeparator (wptr, (String) "", wargs, n);
  1146.   if (NLM_QUIET) {
  1147.     if (Nlm_WindowHasBeenShown (Nlm_ParentWindow (g))) {
  1148.       XtRealizeWidget (h);
  1149.     }
  1150.   } else {
  1151.     XtRealizeWidget (h);
  1152.   }
  1153.   return h;
  1154. }
  1155. #endif
  1156.  
  1157. static void Nlm_NewGroup (Nlm_GrouP g, Nlm_CharPtr title,
  1158.                           Nlm_Int2 width, Nlm_Int2 height,
  1159.                           Nlm_Boolean visible, Nlm_RectPtr pr,
  1160.                           Nlm_FonT font, Nlm_GrpActnProc actn)
  1161.  
  1162. {
  1163.   Nlm_LineTool    bt;
  1164.   Nlm_GroupTool   h;
  1165.   Nlm_LineTool    lf;
  1166.   Nlm_PoinT       pt;
  1167.   Nlm_RecT        r;
  1168.   Nlm_LineTool    rt;
  1169.   Nlm_LineTool    tp;
  1170. #ifdef WIN_MSWIN
  1171.   Nlm_FntPtr      fntptr;
  1172.   Nlm_WindowTool  wptr;
  1173. #endif
  1174.  
  1175.   lf = NULL;
  1176.   tp = NULL;
  1177.   rt = NULL;
  1178.   bt = NULL;
  1179.   Nlm_GetRect ((Nlm_GraphiC) g, &r);
  1180.   if (visible) {
  1181.     pt.x = r.left + 3;
  1182.     pt.y = r.top + Nlm_LineHeight () + 2;
  1183.   } else {
  1184.     pt.x = r.left;
  1185.     pt.y = r.top;
  1186.   }
  1187.   if (visible) {
  1188.     Nlm_LoadBoxData ((Nlm_BoX) g, pt, pt, pt, pt.y, pt.x, 3, 3, 3, 2, width, height);
  1189.   } else {
  1190.     Nlm_LoadBoxData ((Nlm_BoX) g, pt, pt, pt, pt.y, pt.x, 0, 0, 3, 2, width, height);
  1191.   }
  1192.   h = NULL;
  1193.   if (visible) {
  1194. #ifdef WIN_MAC
  1195.     h = Nlm_DependentPrompt ((Nlm_GraphiC) g, pr, title, font, 'l');
  1196. #endif
  1197. #ifdef WIN_MSWIN
  1198.     wptr = Nlm_ParentWindowPtr ((Nlm_GraphiC) g);
  1199.     h = CreateWindow ("Button", title, WS_CHILD | BS_GROUPBOX,
  1200.                       r.left, r.top, r.right - r.left,
  1201.                       r.bottom - r.top, wptr, 0,
  1202.                       Nlm_currentHInst, NULL);
  1203.     if (font != NULL) {
  1204.       fntptr = (Nlm_FntPtr) Nlm_HandLock (font);
  1205.       if (fntptr != NULL && fntptr->handle != NULL) {
  1206.         SetWindowFont (h, fntptr->handle, FALSE);
  1207.       }
  1208.       Nlm_HandUnlock (font);
  1209.     }
  1210. #endif
  1211. #ifdef WIN_MOTIF
  1212.     h = Nlm_DependentPrompt ((Nlm_GraphiC) g, pr, title, font, 'l');
  1213.     lf = Nlm_CreateSeparator (g, &r, 1);
  1214.     tp = Nlm_CreateSeparator (g, &r, 2);
  1215.     rt = Nlm_CreateSeparator (g, &r, 3);
  1216.     bt = Nlm_CreateSeparator (g, &r, 4);
  1217. #endif
  1218.   }
  1219.   Nlm_LoadGroupData (g, h, lf, tp, rt, bt);
  1220.   Nlm_LoadAction ((Nlm_GraphiC) g, (Nlm_ActnProc) actn);
  1221. }
  1222.  
  1223. static Nlm_GrouP Nlm_CreateGroup (Nlm_GrouP prnt, Nlm_Int2 recordSize,
  1224.                                   Nlm_Int2 width, Nlm_Int2 height,
  1225.                                   Nlm_Boolean visible, Nlm_CharPtr title,
  1226.                                   Nlm_FonT font, Nlm_GrpActnProc actn)
  1227.  
  1228. {
  1229.   Nlm_GrouP   g;
  1230.   Nlm_PoinT   npt;
  1231.   Nlm_RecT    pr;
  1232.   Nlm_RecT    r;
  1233.   Nlm_WindoW  tempPort;
  1234.   Nlm_Int2    top;
  1235.   Nlm_Int2    wid;
  1236.  
  1237.   g = NULL;
  1238.   if (prnt != NULL) {
  1239.     tempPort = Nlm_SavePort ((Nlm_GraphiC) prnt);
  1240.     Nlm_GetNextPosition ((Nlm_GraphiC) prnt, &npt);
  1241.     if (font == NULL) {
  1242.       font = Nlm_systemFont;
  1243.     }
  1244.     Nlm_SelectFont (font);
  1245.     wid = Nlm_StringWidth (title);
  1246. #ifdef WIN_MAC
  1247.     top = Nlm_LineHeight ();
  1248. #endif
  1249. #ifdef WIN_MSWIN
  1250.     top = Nlm_LineHeight ();
  1251. #endif
  1252. #ifdef WIN_MOTIF
  1253.     top = Nlm_LineHeight ();
  1254. #endif
  1255.     if (visible) {
  1256.       Nlm_LoadRect (&r, npt.x, npt.y, npt.x + wid + 20, npt.y + 23);
  1257.     } else {
  1258.       Nlm_LoadRect (&r, npt.x, npt.y, npt.x, npt.y);
  1259.     }
  1260.     g = (Nlm_GrouP) Nlm_CreateLink ((Nlm_GraphiC) prnt, &r, recordSize, groupProcs);
  1261.     if (g != NULL) {
  1262.       Nlm_GetRect ((Nlm_GraphiC) g, &r);
  1263.       Nlm_LoadRect (&pr, r.left + 4, r.top, r.left + wid + 6, r.top + top);
  1264.       Nlm_NewGroup (g, title, width, height, visible, &pr, font, actn);
  1265.       Nlm_DoAdjustPrnt ((Nlm_GraphiC) g, &r, TRUE, FALSE);
  1266.       Nlm_DoShow ((Nlm_GraphiC) g, TRUE, FALSE);
  1267.     }
  1268.     Nlm_RestorePort (tempPort);
  1269.   }
  1270.   return g;
  1271. }
  1272.  
  1273. extern Nlm_GrouP Nlm_NormalGroup (Nlm_GrouP prnt, Nlm_Int2 width,
  1274.                                   Nlm_Int2 height, Nlm_CharPtr title,
  1275.                                   Nlm_FonT font, Nlm_GrpActnProc actn)
  1276.  
  1277. {
  1278.   Nlm_GrouP  g;
  1279.  
  1280.   g = Nlm_CreateGroup (prnt, sizeof (Nlm_GroupRec), width,
  1281.                        height, TRUE, title, font, actn);
  1282.   return g;
  1283. }
  1284.  
  1285. extern Nlm_GrouP Nlm_HiddenGroup (Nlm_GrouP prnt, Nlm_Int2 width,
  1286.                                   Nlm_Int2 height, Nlm_GrpActnProc actn)
  1287.  
  1288. {
  1289.   Nlm_GrouP  g;
  1290.  
  1291.   g = Nlm_CreateGroup (prnt, sizeof (Nlm_GroupRec), width,
  1292.                        height, FALSE, "", NULL, actn);
  1293.   return g;
  1294. }
  1295.  
  1296. extern void Nlm_SetGroupMargins (Nlm_GrouP g, Nlm_Int2 xMargin, Nlm_Int2 yMargin)
  1297.  
  1298. {
  1299.   Nlm_BoxData    bdata;
  1300.   Nlm_GroupTool  h;
  1301.   Nlm_PoinT      pt;
  1302.   Nlm_RecT       r;
  1303.  
  1304.   if (g != NULL) {
  1305.     Nlm_GetRect ((Nlm_GraphiC) g, &r);
  1306.     Nlm_GetBoxData ((Nlm_BoX) g, &bdata);
  1307.     bdata.xMargin = xMargin;
  1308.     bdata.yMargin = yMargin;
  1309.     h = Nlm_GetGroupHandle (g);
  1310.     if (h != NULL) {
  1311.       pt.x = r.left + xMargin;
  1312.       pt.y = r.top + Nlm_stdLineHeight + yMargin;
  1313.     } else {
  1314.       pt.x = r.left + xMargin;
  1315.       pt.y = r.top + yMargin;
  1316.     }
  1317.     bdata.nextPoint = pt;
  1318.     bdata.limitPoint = pt;
  1319.     bdata.resetPoint = pt;
  1320.     bdata.nextCol = pt.x;
  1321.     bdata.topRow = pt.y;
  1322.     Nlm_SetBoxData ((Nlm_BoX) g, &bdata);
  1323.   }
  1324. }
  1325.  
  1326. extern void Nlm_SetGroupSpacing (Nlm_GrouP g, Nlm_Int2 xSpacing, Nlm_Int2 ySpacing)
  1327.  
  1328. {
  1329.   Nlm_BoxData  bdata;
  1330.  
  1331.   if (g != NULL) {
  1332.     Nlm_GetBoxData ((Nlm_BoX) g, &bdata);
  1333.     bdata.xSpacing = xSpacing;
  1334.     bdata.ySpacing = ySpacing;
  1335.     Nlm_SetBoxData ((Nlm_BoX) g, &bdata);
  1336.   }
  1337. }
  1338.  
  1339. extern void Nlm_FreeGroup (void)
  1340.  
  1341. {
  1342.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemFree (gphprcsptr);
  1343. }
  1344.  
  1345. extern void Nlm_InitGroup (void)
  1346.  
  1347. {
  1348.   gphprcsptr = (Nlm_GphPrcsPtr) Nlm_MemNew (sizeof (Nlm_GphPrcs) * 1);
  1349.  
  1350.   groupProcs = &(gphprcsptr [0]);
  1351. #ifdef WIN_MAC
  1352.   groupProcs->click = Nlm_GroupClick;
  1353.   groupProcs->key = Nlm_GroupKey;
  1354.   groupProcs->draw = Nlm_DrawGroup;
  1355.   groupProcs->idle = Nlm_IdleGroup;
  1356. #endif
  1357.   groupProcs->show = Nlm_ShowGroup;
  1358.   groupProcs->hide = Nlm_HideGroup;
  1359.   groupProcs->enable = Nlm_EnableGroup;
  1360.   groupProcs->disable = Nlm_DisableGroup;
  1361.   groupProcs->activate = Nlm_ActivateGroup;
  1362.   groupProcs->deactivate = Nlm_DeactivateGroup;
  1363.   groupProcs->remove = Nlm_RemoveGroup;
  1364.   groupProcs->reset = Nlm_ResetGroup;
  1365.   groupProcs->countItems = Nlm_CountGroupItems;
  1366.   groupProcs->linkIn = Nlm_LinkIn;
  1367.   groupProcs->adjustPrnt = Nlm_FinishItemPositioning;
  1368.   groupProcs->setTitle = Nlm_SetGroupTitle;
  1369.   groupProcs->getTitle = Nlm_GetGroupTitle;
  1370.   groupProcs->setValue = Nlm_SetGroupValue;
  1371.   groupProcs->getValue = Nlm_GetGroupValue;
  1372.   groupProcs->setStatus = Nlm_SetGroupStatus;
  1373.   groupProcs->getStatus = Nlm_GetGroupStatus;
  1374.   groupProcs->setPosition = Nlm_SetGroupPosition;
  1375.   groupProcs->getPosition = Nlm_GetGroupPosition;
  1376.   groupProcs->gainFocus = Nlm_GroupGainFocus;
  1377.   groupProcs->loseFocus = Nlm_GroupLoseFocus;
  1378. }
  1379.